package com.linxz.video.videoplayer;

import android.view.ViewGroup;
import com.linxz.video.videoplayer.event.SDKSlotListener;
import com.linxz.video.videoplayer.event.VideoContextInterface;

/**
 * @author Linxz
 * 创建日期：2019年10月15日 19:39
 * version：v4.5.4
 * 描述：
 */
public class VideoAdContext implements SDKSlotListener {

    private ViewGroup mParentView;
    private VideoAdSlot mVideoAdSlot;
    private String sourcePath;
    private VideoContextInterface mListener;

    public VideoAdContext(ViewGroup parentView,String sourcePath){
        this.mParentView=parentView;
        this.sourcePath=sourcePath;
        load();
    }

    public void load() {
        if (sourcePath != null) {
            mVideoAdSlot = new VideoAdSlot(sourcePath, this);
        } else {
            mVideoAdSlot = new VideoAdSlot(null, this); //创建空的slot,不响应任何事件
            if (mListener != null) {
                mListener.onVideoFailed();
            }
        }
    }

    public void setListener(VideoContextInterface mListener) {
        this.mListener = mListener;
    }

    public void onDestory(){
        mVideoAdSlot.destroy();
    }

    public void mute(boolean isMute){
        mVideoAdSlot.mute(isMute);
    }


    @Override
    public ViewGroup getAdParent() {
        return mParentView;
    }

    @Override
    public void onVideoLoadSuccess() {
        if (mListener != null) {
            mListener.onVideoSuccess();
        }
    }

    @Override
    public void onVideoFailed() {
        if (mListener != null) {
            mListener.onVideoFailed();
        }
    }

    @Override
    public void onVideoComplete() {
        if (mListener != null) {
            mListener.onVideoComplete();
        }
    }
}
